
var CarSprite = cc.Sprite.extend ({
        onEnter : function() {
                this._super();
                this.addTouchListen(); 
        },

    onExit : function(){
            this._super();

    },

    removeListener : function() {
            cc.eventManager.removeListeners(this);
    },

    addTouchListen : function() {
            this.touchlistener = cc.EventListener.create({
                    event : cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: false,
            onTouchBegan : this.onTouchBegan,

            onTouchMoved : this.onTouchMoved,

            onTouchEnded : this.onTouchEnded ,

            onTouchesEnded : this.onTouchesEnded,

            onTouchCancelled : this.onTouchCancelled,
            });

            cc.eventManager.addListener(this.touchlistener, this); 
    },

    onTouchBegan : function(touch, event) {
            var target = event.getCurrentTarget();
            var pos = touch.getLocation();
            if (cc.rectContainsPoint(target.getBoundingBox(), pos)) {
                    var target = event.getCurrentTarget();
                    console.log("onTouchBegan....");
                    return true;
            }
            else { 
                    console.log("onTouchBegan return false....");
                    return false;
            }
    },

    onTouchMoved : function(touch, event) {
            
            var target = event.getCurrentTarget();
            //console.log("onTouchMoved....");
            var target = event.getCurrentTarget();
            var delta = touch.getDelta();
            //target.x += delta.x;
            //target.y += delta.y;
            target.x = touch.getLocationX();

            var y = touch.getLocationY();
            //if (target.getBoundingBox().y > 0) { 
            //        y = 0;
            //}
            if (y > target.height / 8) {
                    y = target.height / 8;
            }

            target.y = y; 
            var dis = Math.abs(delta.x);//Math.sqrt(delta.x*delta.x + delta.y*delta.y);
            //target.getParent().addDis(dis);
            //target.getParent().checkHit();
            //console.log("dis:"+dis + " dx:" + delta.x + " dy:"+ delta.y);
    },

    onTouchEnded : function(touch, event) {
            console.log("onTouchEnded....");
    },

    onTouchesEnded : function(touches, event) {
            console.log("onTouchesEnded...");
    },

    onTouchCancelled : function (touch, event) {
            console.log("onTouchCancelled...");
    }



});
